/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package fs.genomemap;

import genomemap.data.ChData;
import genomemap.data.GDataSource;
import genomemap.data.Gene;

import javautil.collections.ArrayUtil;

import java.io.File;
import java.io.IOException;
import java.util.LinkedHashSet;

/**
 * @author Susanta Tewari
 * @version 1.0
 * @created 08-Nov-2007 8:44:01 PM
 */
public class G_FileDataSource extends GDataSource {

    /** Field description */
    private ChData chData = null;

    /** Field description */
    private LinkedHashSet<Gene> fullGeneSet = null;

    /**
     * Constructs ...
     */
    public G_FileDataSource() {}

    /**
     * Constructs ...
     *
     * @param ch_id description
     * @param order description
     * @param chData description
     */
    public G_FileDataSource(int ch_id, int[] order, ChData chData) {

        setChId(ch_id);
        setOrder(order);
        setChData(chData);
    }

    @Override
    public void loadData() {

        int[][] data = null;

        try {

            data = ArrayUtil.get2DIntMArray(new File(getChData().getRflpDataFilePath()), false,
                                            ",");

        } catch (NumberFormatException | IOException ex) {
            ex.printStackTrace();
        }

        setRflpData(Imputation(data));
    }

    ChData getChData() {
        return chData;
    }

    public void setChData(ChData chData) {
        this.chData = chData;
    }

    @Override
    public LinkedHashSet<Gene> getFullGeneSet() {

        if (fullGeneSet == null) {
            fullGeneSet = new LinkedHashSet<>(FileSettings.load().getGeneSet(getChId()));
        }

        return fullGeneSet;
    }
}
